package com.lonely.fx.dialog;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

import java.util.Optional;
import java.util.function.Consumer;

/**
 * @date: 2022-08-01 16:40
 * @author: ztkj-hzb
 * @description: 一个普通的文本提示框
 **/
public class AlertSettingMain extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    /**
     *
     */
    @Override
    public void start(Stage primaryStage) throws Exception {

        HBox hBox = new HBox();
        Button button = new Button("点击打开弹框");
        hBox.getChildren().addAll(button);
        primaryStage.setScene(new Scene(hBox));
        primaryStage.setWidth(600);
        primaryStage.setHeight(500);
        primaryStage.show();

        button.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {

                //创建一个对话框实例
                Alert alert = new Alert(Alert.AlertType.NONE);

                //设置弹框类型---异常情况
                alert.setAlertType(Alert.AlertType.INFORMATION);

                //
                alert.setContentText("dfafdfa");

                Optional<ButtonType> optional = alert.showAndWait();
                optional.ifPresent(new Consumer<ButtonType>() {
                    @Override
                    public void accept(ButtonType buttonType) {
                        if(buttonType == ButtonType.OK){
                            System.out.println("点击了确定按钮");
                        }
                    }
                });

            }
        });

    }
}
